﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ad_admanage.aspx.cs" Inherits="backmanage_adsystem_ad_admanage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>广告管理</title>
    <script type="text/javascript" src="../js/jquery-1.6.1.js"></script>
	<link rel="stylesheet" href="../css/jquery.ui.all.css" />
	<script type="text/javascript" src="../external/jquery.bgiframe-2.1.2.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.core.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.widget.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.mouse.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.button.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.draggable.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.position.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.resizable.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.dialog.js"></script>
	<script type="text/javascript" src="../js/jquery.ui.datepicker.js"></script>
	<script type="text/javascript" src="../js/jquery.effects.core.js"></script>
	<script type="text/javascript" src="../js/jquery.ajax.upfile.js"></script>
	<link rel="stylesheet" href="../css/demos.css" />  
    <script type="text/javascript">
    $(function(){
		       $("#begintime" ).datepicker();
		       $("#endtime" ).datepicker();
               $("#create-form").dialog("destory");
               $("#windows-info").dialog("destory");
               $("#create-form").dialog({
                        autoOpen:false,
                        height:270,
                        width:350,
                        modal:true,
                        buttons:{
                                 "提交":function(){
                                       AdAdd();
                                       AdList();
                                       $(this).dialog("close");
                                 },
                                 "取消":function(){$(this).dialog("close");},
                                 },
               });
               $("#create-user").button().click(function(){
                  $("#begintime").show();
                  $("#create-form input:text").val("");
                  $("#adImg").attr("src","#");
                  $("#create-form").dialog("open");
               });
               function AdpositionList()
               {
                  $.ajax({
                          async:false,
                          url:'../API/A_Admanage.aspx',
                          type:'POST',
                          data:{edit:'positionlist'},
                          success:function(msg)
                          {
                             $("#create-form select").text("");
                             $("#create-form select").append(msg);
                          }
                  });
               }
               function AdList()
               {
                 $.ajax({
                         async:false,
                         url:'../API/A_Admanage.aspx',
                         type:'POST',
                         data:{edit:'list'},
                         success:function(msg)
                         {
                            $("#adlist tbody").text("");
                            $("#adlist tbody").append(msg);
                            $("#adlist a.edit").click(function(){
                                   var i=$(this).parent().parent().attr("id"); 
                                   AdEdit(i)
                                   SetEditWindows(i);
                                   $("#begintime").hide();
                                   $("#create-form").dialog("open");
                            });
                            $("#adlist a.state").click(function(){
                                   var i=$(this).parent().parent().attr("id"); 
                                   SetStateWindows(i);
                                   $("#windows-info").dialog("open");
                            });
                         }
                 });
               }
               function AdAdd()
               {
                 var begintime=$("#begintime").val();
                 var endtime=$("#endtime").val();
                 var title=$("#title").val();
                 var imgurl=$("#adImg").attr("src");
                 var url=$("#url").val();
                 var positionid=$("#adposition").find("option:selected").attr("value");
                 var state;
                 var c=$("#create-form input:checked");
                 if(c.length>0)
                  {
                       state=1;
                  }
                 else
                  {
                       state=0;
                  }
                  $.ajax({
                          async:false,
                          url:'../API/A_Admanage.aspx',
                          type:'POST',
                          data:{
                                edit:'add',
                                bt:begintime,
                                et:endtime,
                                t:title,
                                iu:imgurl,
                                u:url,
                                s:state,
                                p:positionid,
                          },
                          success:function(msg)
                          {
                             alert(msg);
                          }
                  });
               }
               function del()
               {
                 var c=$("#adlist input:checked");
                    var b=new Array();
                    for(var i=0;i<c.length;i++)
                    {
                      b[i]=c[i].value;
                    }
                    if(b.length>0)
                    {
                      $.ajax({
                             async:false,
                             url:'../API/A_Admanage.aspx',
                             type:'POST',
                             data:{edit:'del',id:b},
                             success:function(msg)
                             {
                                AdList();
                                //alert(msg);
                             }
                      });
                    }
                    else
                    {
                       alert("请先选择.");
                    }
               }
               function AdUpdate(id)
               {
                  var imgurl=$("#adImg").attr("src");
                  var endtime=$("#endtime").val();
                  var position=$("#adposition").find("option:selected").attr("value");
                  var title=$("#title").val();
                  var url=$("#url").val();
                  var state;
                  var c=$("#create-form input:checked");
                  if(c.length>0)
                  {
                       state=1;
                  }
                  else
                  {
                       state=0;
                  }
                  $.ajax({
                          async:false,
                          url:'../API/A_Admanage.aspx',
                          type:'POST',
                          data:{
                                edit:'update',
                                id:id,
                                et:endtime,
                                iu:imgurl,
                                p:position,
                                s:state,
                                t:title,
                                u:url,
                          },
                          success:function(msg)
                          {
                             //alert(msg);
                          }
                          
                  });
               }
               function allyes()
               {
                 $("#adlist input:checkbox").attr("checked",true);
               }
               function allno()
               {
                 $("#adlist input:checkbox").removeAttr("checked");
               }
               function AdUpdateState(id)
               {
                 var state=$("#"+id+" a.state").text();
                  $.ajax({
                          async:false,
                          url:'../API/A_Admanage.aspx',
                          type:'POST',
                          data:{
                                edit:'state',
                                id:id,
                                s:state,
                          },
                          success:function(msg)
                          {
                             //alert(msg);
                          }
                  });
               }
               function SetStateWindows(id)
               {
               $("#windows-info").dialog({
                          autoOpen:false,
                          height:130,
                          width:230,
                          modal:true,
                          resizable:false,
                          buttons:{
                                  "确定":function(){
                                       AdUpdateState(id);
                                       $(this).dialog("close");
                                       AdList();
                                  },
                                  "取消":function(){
                                       $(this).dialog("close");
                                  },
                          },
               });
               }
               function SetEditWindows(id)
               {
               $("#create-form").dialog({
                        autoOpen:false,
                        height:270,
                        width:350,
                        modal:true,
                        resizable:false,
                        buttons:{
                                 "修改":function(){
                                       $(this).dialog("close");
                                       AdUpdate(id);
                                       AdList();
                                 },
                                 "取消":function(){$(this).dialog("close");},
                                 },
               });
               }
               function AdEdit(id)
               {
                 var t=$("#"+id+" a.title").text();
                 var u=$("#"+id+" a.title").attr("title");
                 var et=$("#"+id+" span.endtime").text();
                 var p=$("#"+id+" span.position").attr("title");
                 var s=$("#"+id+" a.state").text();
                 var iu=$("#"+id).attr("title");
                 if(s=="true")
                  {
                    $("#create-form input:checkbox").attr("checked",true);
                  }
                  else
                  {
                    $("#create-form input:checkbox").removeAttr("checked");
                  }
                  $('#create-form select').attr('value',p);
                  $("#title").val(t);
                  $("#url").val(u);
                  $("#endtime").val(et);
                  $("#adImg").attr("src",iu);
               }
               function ajaxFileUpload()
               {
                    $.ajaxFileUpload(
                                   {
                                url:'../API/A_Fileupload.aspx?uptype=0',            
                                secureuri:false,
                                fileElementId:'fup',
                                data:{uptype:'0'},
                                dataType: 'json',                                  
                                success: function (data, status)
                                {
                                    if(data.err=="")
                                    {
                                        document.getElementById("adImg").src=data.msg;
                                    }
                                    else
                                    {
                                        alert(data.err);
                                    }
                                },
                                error: function (data, status, e)
                                {
                                    alert("上传失败!");
                                }
                            });
               }
               $("#del").click(function(){del();});
               $("#allyes").click(function(){allyes();});
               $("#allno").click(function(){allno();});
               $("#upload").click(function(){ajaxFileUpload();});
               $(document).ready(function(){
                               AdpositionList();
                               AdList();
               });
               
    })
    </script>
    <style type="text/css">
    .create-form{ display:none;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    广告管理<a id="create-user">添加广告</a>
    <table id="adlist">
      <thead>
        <tr>
          <td>操作</td>
          <td>描述</td>
          <td>广告位</td>
          <td>开始时间</td>
          <td>结束时间</td>
          <td>浏览量</td>
          <td>点击量</td>
          <td>状态</td>
          <td>编辑</td>
        </tr>
      </thead>
      <tbody>
      
      </tbody>
      <tfoot>
         <tr>
           <td colspan="10">一共0条 10条/页<input type="button" id="del" value="删除" /><input type="button" id="allyes" value="全选" /><input type="button" id="allno" value="全不选" /></td>
         </tr>
      </tfoot>
    </table>
    </div>
    <div id="create-form" class="create-form" title="添加广告">
    <img src="" alt="" id="adImg" /><br />
    图片：<input id="fup" name="fup" type="file" style="width:100px" /><input type="button" id="upload" value="上传"/><br />
    广告描述：<input type="text" id="title" /><br />
    广告链接：<input type="text" id="url" /><br />
    开始时间：<input type="text" id="begintime" /><br />
    结束时间：<input type="text" id="endtime" /><br />
    广告位置：<select id="adposition"></select><br />
    可用状态：<input type="checkbox" id="state" />
    </div>
    <div id="windows-info" class="create-form" title="系统提示">
    <p>确定要修改广告的可用状态？</p>
    </div>
    </form>
</body>
</html>
